<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/17 0017
  Time: 下午 3:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<form class="layui-form" action="/shop/saveCommodity">
    <input name="cardId" value="${cardId}" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label ">订单编号:</label> <label class="layui-form-label">${cardId}</label>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">卡号</label>
        <div class="layui-input-block">
            <input type="text" name="cardNumber" required
                   placeholder="请输入卡号" autocomplete="off" class="layui-input" value="${record.cardNumber}">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">卡密</label>
        <div class="layui-input-block">
            <input type="text" name="cardPassword" required
                   placeholder="请输入卡密" autocomplete="off" class="layui-input" value="${record.cardPassword}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">推送平台:</label>

        <div class="layui-input-block">
            <input type="text" required
                   disabled autocomplete="off" class="layui-input" value="${record.sendWebSite}">
        </div>

    </div>


    <div class="layui-form-item">
        <label class="layui-form-label ">当前状态:</label>
        <div class="layui-input-block">
            <input type="text" required
                   disabled autocomplete="off" class="layui-input" value="${record.cardStr}">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单信息</label>
            <div class="layui-input-block">
                <input type="text" name="cardMsg" value="${record.cardMsg}" class="layui-input"/>
            </div>
        </div>
    </div>
    <input type="hidden" value ="${record.cardState}" name = 'cardState'/>
    <div class="layui-form-item">
        <label class="layui-form-label ">修改状态:</label>
        <div class="layui-input-block">
            <select name="newCardState" lay-verify="">
                <%--case "0":--%>
                <%--temp.set("cardStr", "处理中");--%>
                <%--break;--%>
                <%--case "1":--%>
                <%--temp.set("cardStr", "处理中");--%>
                <%--break;--%>
                <%--case "2":--%>
                <%--temp.set("cardStr", "处理中");--%>
                <%--break;--%>
                <%--case "3":--%>
                <%--temp.set("cardStr", "交易失败");--%>
                <%--break;--%>
                <%--case "4":--%>
                <%--temp.set("cardStr", "交易成功");--%>
                <%--break;--%>
                <%--case "5":--%>
                <%--temp.set("cardStr", "已打款");--%>
                <%--break;--%>
                <%--case "6":--%>
                <%--temp.set("cardStr", "交易失败");--%>
                <option value="-1" selected>变更状态</option>
                <option value="1">处理中</option>

                <option value="2">交易成功</option>

                <option value="3">交易失败</option>

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">面值</label>
        <div class="layui-input-block">

            <input type="number"    name="faceValue"
                   disabled autocomplete="off" class="layui-input" value="${record.feedbackValue}">

        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">折扣</label>
        <div class="layui-input-block">

            <input type="number" name="discount" required
                   placeholder="请输入折扣" autocomplete="off"  onkeyup="setMoney(this.value)" class="layui-input" value="${record.discount}">
            <script>
                function setMoney(discount){
                    var facevalue=$("input[name='faceValue']").val();
                    $("input[name='amount']").val(discount*facevalue);

                }

            </script>
        </div>
    </div>

    <c:choose>
        <c:when test="${record.alipay.alipayId!=null&&record.alipay.alipayId!=''}">

            <div class="layui-form-item">
                <label class="layui-form-label">支付宝ID</label>
                <div class="layui-input-block">
                    <input type="text" disabled name="alipayId" value="${record.alipay.alipayId}" class="layui-input"/>
                </div>
            </div>

        </c:when>
        <c:when test="${record.alipay.alipayId==null||record.alipay.alipayId==''}">

            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="realName" value="${record.alipay.realName}" class="layui-input"/>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">支付宝账户</label>
                <div class="layui-input-block">
                    <input type="text" name="alipayAccount" value="${record.alipay.alipayAccount}" class="layui-input"/>
                </div>
            </div>

        </c:when>
    </c:choose>

    <div class="layui-form-item">
        <label class="layui-form-label">支付金额</label>
        <div class="layui-input-block">
            <input type="number" name="amount"
                    value="<fmt:formatNumber type="number" value="${record.alipay.money}" pattern="#.00" />"
                    class="layui-input"/>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <%--<button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
        </div>
    </div>
</form>

<script>

    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {

            console.log(data.field);
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: '/shop/saveCardOrder',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: data.field,
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success: function (data) {

                    if (data.result) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);

                    } else {
                        layer.msg(data.msg, {time: 2000, icon: 5});
                    }
                    //console.log(data)
                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete: function () {
                    //console.log('结束')
                }
            });
            return false;
        });
    });
</script>


</body>
</html>
